package gov.tax.rti.base.job;

import gov.tax.rti.ext.bdf2.utils.CompanyIdUtil;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.bstek.bdf2.job.model.JobDefinition;
import com.bstek.bdf2.job.service.IJobDataService;

@Component
public class Bdf2JobDataService implements IJobDataService{
	
	public String getCompanyId() {
		return CompanyIdUtil.getCompanyId();
	}

	public List<JobDefinition> filterJobs(List<JobDefinition> jobDefinitions) {
		if(jobDefinitions == null) return jobDefinitions;
		List<JobDefinition> filterJobs = new ArrayList<JobDefinition>();
		for (JobDefinition jobDefinition : jobDefinitions) {
			String companyId = jobDefinition.getCompanyId();
			if(!getCompanyId().equals(companyId)){
				continue;
			}
			/*String beanId = jobDefinition.getBeanId();
			if(StringUtils.isNotEmpty(beanId)){
				try{
					if(this.applicationContext.getBean(beanId) == null){
						continue;
					}
				}catch(NoSuchBeanDefinitionException e){
					continue;
				}
			}*/
			filterJobs.add(jobDefinition);
		}
		return filterJobs;
	}

	/* implements ApplicationContextAware
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}
	private ApplicationContext applicationContext;*/
}